package com.practice.bootdemo.controller;

import com.practice.bootdemo.dto.UserDto;
import com.practice.bootdemo.eventdto.UserDtoEvent;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;

/**
 * @author :Administrator
 * @description: TODO edit class Description
 * @create date: 2021/10/29 18:25
 */
@RestController
@RequestMapping(value = "eventSend")
public class EventSendController {

    @Autowired
    private ApplicationContext applicationContext;

    @RequestMapping(value = "sendmsg", method = RequestMethod.GET)
    public void delete(String name) {
        name += Thread.currentThread().getName();
        UserDto userDto = UserDto.builder().name(name).age(12).createDate(new Date()).build();
        UserDtoEvent userDtoEvent = new UserDtoEvent(this, userDto);
        applicationContext.publishEvent(userDtoEvent);
    }

}
